<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>企业登录系统</title>
    <style>
        /* 重置默认样式，确保在不同浏览器中显示一致 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box; /* 使元素的内边距和边框包含在宽度和高度内 */
        }

        /* 页面主体样式 */
        body {
            /* 设置字体族，按优先级使用 */
            font-family: "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            /* 设置渐变背景 */
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            /* 确保最小高度占满整个视口 */
            min-height: 100vh;
            /* 使用弹性布局使内容居中 */
            display: flex;
            align-items: center;
            justify-content: center;
        }

        /* 登录容器样式 */
        .login-container {
            background: white;
            border-radius: 10px; /* 圆角边框 */
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.1); /* 添加阴影效果 */
            width: 100%;
            max-width: 400px; /* 最大宽度限制 */
            padding: 40px;
            margin: 20px;
        }

        /* 登录头部样式 */
        .login-header {
            text-align: center;
            margin-bottom: 30px;
        }

        .login-header h1 {
            color: #2c3e50; /* 深色标题 */
            font-size: 24px;
            margin-bottom: 10px;
        }

        .login-header p {
            color: #7f8c8d; /* 浅色副标题 */
            font-size: 14px;
        }

        /* 表单组样式 */
        .form-group {
            margin-bottom: 20px;
        }

        .form-group label {
            display: block;
            color: #34495e;
            margin-bottom: 8px;
            font-size: 14px;
        }

        /* 输入框样式 */
        .form-group input {
            width: 100%;
            padding: 12px;
            border: 1px solid #ddd;
            border-radius: 5px;
            font-size: 14px;
            transition: border-color 0.3s ease; /* 添加过渡效果 */
        }

        /* 输入框焦点样式 */
        .form-group input:focus {
            border-color: #3498db;
            outline: none;
            box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2); /* 添加焦点光晕效果 */
        }

        /* 记住我和忘记密码区域样式 */
        .remember-forgot {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
            font-size: 14px;
        }

        .remember-me {
            display: flex;
            align-items: center;
        }

        .remember-me input {
            margin-right: 5px;
        }

        /* 忘记密码链接样式 */
        .forgot-password {
            color: #3498db;
            text-decoration: none;
        }

        .forgot-password:hover {
            text-decoration: underline;
        }

        /* 登录按钮样式 */
        .login-button {
            width: 100%;
            padding: 12px;
            background: #3498db;
            color: white;
            border: none;
            border-radius: 5px;
            font-size: 16px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        .login-button:hover {
            background: #2980b9;
        }

        /* 登录页脚样式 */
        .login-footer {
            text-align: center;
            margin-top: 20px;
            font-size: 14px;
            color: #7f8c8d;
        }

        .login-footer a {
            color: #3498db;
            text-decoration: none;
        }

        .login-footer a:hover {
            text-decoration: underline;
        }

        /* 响应式设计：移动设备适配 */
        @media (max-width: 480px) {
            .login-container {
                margin: 10px;
                padding: 20px;
            }
        }

        /* 错误提示样式 */
        .error-message {
            color: #e74c3c;
            font-size: 12px;
            margin-top: 5px;
            display: none;
        }

        /* 加载动画样式 */
        .loading {
            display: none;
            text-align: center;
            margin-top: 10px;
        }

        /* 加载动画旋转效果 */
        .loading::after {
            content: "";
            display: inline-block;
            width: 20px;
            height: 20px;
            border: 2px solid #f3f3f3;
            border-top: 2px solid #3498db;
            border-radius: 50%;
            animation: spin 1s linear infinite;
        }

        /* 定义旋转动画 */
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        /* 验证码相关样式 */
        .captcha-group {
            display: flex;
            gap: 10px;
            align-items: flex-start;
        }

        .captcha-group input {
            flex: 1;
        }

        .captcha-image {
            height: 44px;
            border-radius: 5px;
            cursor: pointer;
            border: 1px solid #ddd;
        }

        .captcha-image:hover {
            opacity: 0.8;
        }

        /* 验证码错误提示样式 */
        .captcha-error {
            color: #e74c3c;
            font-size: 12px;
            margin-top: 5px;
            display: none;
        }
    </style>
</head>
<body>
    <!-- 登录容器 -->
    <div class="login-container">
        <!-- 登录头部 -->
        <div class="login-header">
            <h1>企业管理系统</h1>
            <p>欢迎回来，请登录您的账号</p>
        </div>

        <!-- 登录表单 -->
        <form id="loginForm" onsubmit="return handleLogin(event)">
            <!-- 用户名输入组 -->
            <div class="form-group">
                <label for="username">用户名</label>
                <input 
                    type="text" 
                    id="username" 
                    name="username" 
                    placeholder="请输入用户名"
                    required
                >
                <div class="error-message" id="username-error"></div>
            </div>

            <!-- 密码输入组 -->
            <div class="form-group">
                <label for="password">密码</label>
                <input 
                    type="password" 
                    id="password" 
                    name="password" 
                    placeholder="请输入密码"
                    required
                >
                <div class="error-message" id="password-error"></div>
            </div>

            <!-- 添加验证码输入组 -->
            <div class="form-group">
                <label for="captcha">验证码</label>
                <div class="captcha-group">
                    <input 
                        type="text" 
                        id="captcha" 
                        name="captcha" 
                        placeholder="请输入验证码"
                        required
                    >
                    <img 
                        id="captchaImage" 
                        class="captcha-image" 
                        alt="验证码"
                        onclick="refreshCaptcha()"
                    >
                </div>
                <div class="captcha-error" id="captcha-error"></div>
            </div>

            <!-- 记住我和忘记密码区域 -->
            <div class="remember-forgot">
                <label class="remember-me">
                    <input type="checkbox" name="remember"> 记住我
                </label>
                <a href="#" class="forgot-password">忘记密码？</a>
            </div>

            <!-- 登录按钮和加载动画 -->
            <button type="submit" class="login-button">登录</button>
            <div class="loading" id="loading"></div>
        </form>

        <!-- 登录页脚 -->
        <div class="login-footer">
            <p>还没有账号？ <a href="#">立即注册</a></p>
        </div>
    </div>

    <script>
        // 生成随机验证码
        function generateCaptcha() {
            const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
            let captcha = '';
            for (let i = 0; i < 4; i++) {
                captcha += chars.charAt(Math.floor(Math.random() * chars.length));
            }
            return captcha;
        }

        // 创建验证码图片
        function createCaptchaImage(text) {
            const canvas = document.createElement('canvas');
            canvas.width = 100;
            canvas.height = 40;
            const ctx = canvas.getContext('2d');

            // 设置背景
            ctx.fillStyle = '#f0f0f0';
            ctx.fillRect(0, 0, canvas.width, canvas.height);

            // 添加干扰线
            for (let i = 0; i < 3; i++) {
                ctx.beginPath();
                ctx.moveTo(Math.random() * canvas.width, Math.random() * canvas.height);
                ctx.lineTo(Math.random() * canvas.width, Math.random() * canvas.height);
                ctx.strokeStyle = `rgb(${Math.random() * 255},${Math.random() * 255},${Math.random() * 255})`;
                ctx.stroke();
            }

            // 添加干扰点
            for (let i = 0; i < 50; i++) {
                ctx.fillStyle = `rgb(${Math.random() * 255},${Math.random() * 255},${Math.random() * 255})`;
                ctx.fillRect(Math.random() * canvas.width, Math.random() * canvas.height, 2, 2);
            }

            // 绘制验证码文字
            ctx.font = 'bold 24px Arial';
            ctx.fillStyle = '#333';
            ctx.textAlign = 'center';
            ctx.textBaseline = 'middle';
            for (let i = 0; i < text.length; i++) {
                const x = 20 + i * 20;
                const y = 20;
                const rotate = (Math.random() - 0.5) * 0.3;
                ctx.translate(x, y);
                ctx.rotate(rotate);
                ctx.fillText(text[i], 0, 0);
                ctx.rotate(-rotate);
                ctx.translate(-x, -y);
            }

            return canvas.toDataURL();
        }

        // 刷新验证码
        function refreshCaptcha() {
            const captcha = generateCaptcha();
            window.currentCaptcha = captcha; // 存储当前验证码
            const captchaImage = document.getElementById('captchaImage');
            captchaImage.src = createCaptchaImage(captcha);
        }

        // 页面加载时生成验证码
        window.onload = function() {
            refreshCaptcha();
        };

        // 处理登录表单提交
        function handleLogin(event) {
            event.preventDefault();
            
            // 获取表单数据
            const username = document.getElementById('username').value;
            const password = document.getElementById('password').value;
            const captcha = document.getElementById('captcha').value;
            
            // 验证码验证
            if (captcha.toLowerCase() !== window.currentCaptcha.toLowerCase()) {
                document.getElementById('captcha-error').textContent = '验证码错误';
                document.getElementById('captcha-error').style.display = 'block';
                refreshCaptcha(); // 刷新验证码
                return false;
            }
            
            // 显示加载动画
            document.getElementById('loading').style.display = 'block';
            
            // 模拟登录请求
            setTimeout(() => {
                // 这里应该是实际的登录请求
                console.log('登录信息：', { username, password, captcha });
                
                // 隐藏加载动画
                document.getElementById('loading').style.display = 'none';
                
                // 模拟登录成功
                alert('登录成功！');
            }, 1500);
            
            return false;
        }

        // 用户名输入验证
        document.getElementById('username').addEventListener('input', function() {
            const error = document.getElementById('username-error');
            if (this.value.length < 3) {
                error.textContent = '用户名至少需要3个字符';
                error.style.display = 'block';
            } else {
                error.style.display = 'none';
            }
        });

        // 密码输入验证
        document.getElementById('password').addEventListener('input', function() {
            const error = document.getElementById('password-error');
            if (this.value.length < 6) {
                error.textContent = '密码至少需要6个字符';
                error.style.display = 'block';
            } else {
                error.style.display = 'none';
            }
        });

        // 验证码输入验证
        document.getElementById('captcha').addEventListener('input', function() {
            const error = document.getElementById('captcha-error');
            if (this.value.length !== 4) {
                error.textContent = '验证码必须是4个字符';
                error.style.display = 'block';
            } else {
                error.style.display = 'none';
            }
        });
    </script>
</body>
</html>